home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / Wood.0.72 / Sources / PageMargin.m < prev    next >
Encoding:
Text File  |  1994-06-03  |  4.1 KB  |  147 lines

  1.  
  2. #import <appkit/Application.h>
  3. #import <appkit/Cell.h>
  4. #import <appkit/Matrix.h>
  5. #import <appkit/PrintInfo.h>
  6.  
  7. #import "PageMargin.h"
  8. #import "DGPrintInfo.h"
  9.  
  10. @implementation PageMargin
  11. /*
  12.  * PageLayout is overridden so that the user can set the margins of
  13.  * the page.  This is a useful feature in most programs.
  14.  *
  15.  * The accessory view is used to add the additional fields, and
  16.  * pickedUnits: is overridden so that the margin is displayed in the
  17.  * currently selected units.  Note that the accessoryView is set
  18.  * in InterfaceBuilder using the outlet mechanism!
  19.  */
  20.  
  21.  
  22. /* Get the values from the fields */
  23. - getValues:(float *)lm right:(float *)rm top:(float *)tm bottom:(float *)bm
  24. {
  25.     float conversion, dummy;
  26.     [self convertOldFactor:&conversion newFactor:&dummy];
  27. /* Values are returned in points, just like PrintInfo */
  28.     *lm = [leftMargin floatValue] / conversion;
  29.     *rm = [rightMargin floatValue] / conversion;
  30.     *tm = [topMargin floatValue] / conversion;
  31.     *bm = [bottomMargin floatValue] / conversion;
  32.     return self;
  33. }
  34.  
  35. /* Set the values as passed */
  36. - setValues:(float)lm right:(float)rm top:(float)tm bottom:(float)bm
  37. {
  38.     float conversion, dummy;
  39.     [self convertOldFactor:&conversion newFactor:&dummy];
  40. /* Values are set in Points, just like PrintInfo */
  41.     [leftMargin setFloatValue:lm*conversion];
  42.     [rightMargin setFloatValue:rm*conversion];
  43.     [topMargin setFloatValue:tm*conversion];
  44.     [bottomMargin setFloatValue:bm*conversion];
  45.     return self;
  46. }
  47.  
  48.  
  49. - pickedUnits:sender
  50. /*
  51.  * Called when the user selects different units (e.g. cm or inches).
  52.  * Must update the margin fields.
  53.  */
  54. {
  55.     float old, new;
  56.  
  57.     [self convertOldFactor:&old newFactor:&new];
  58.     [leftMargin setFloatValue:new * [leftMargin floatValue] / old];
  59.     [rightMargin setFloatValue:new * [rightMargin floatValue] / old];
  60.     [topMargin setFloatValue:new * [topMargin floatValue] / old];
  61.     [bottomMargin setFloatValue:new * [bottomMargin floatValue] / old];
  62.  
  63.     return [super pickedUnits:sender];
  64. }
  65.  
  66. - readPrintInfo
  67. /*
  68.  * Sets the margin fields from the Application-wide PrintInfo.
  69.  */
  70. {
  71.     id pi;
  72.     float conversion, dummy;
  73.     NXCoord left, right, top, bottom;
  74.  
  75.     [super readPrintInfo];
  76.     pi = [NXApp printInfo];
  77.     [self convertOldFactor:&conversion newFactor:&dummy];
  78.     [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
  79.     [leftMargin setFloatValue:left * conversion];
  80.     [rightMargin setFloatValue:right * conversion];
  81.     [topMargin setFloatValue:top * conversion];
  82.     [bottomMargin setFloatValue:bottom * conversion];
  83.     return self;
  84. }
  85.  
  86. - writePrintInfo
  87. /*
  88.  * Sets the margin values in the Application-wide PrintInfo from
  89.  * the margin fields in the panel.
  90.  */
  91. {
  92.     id pi;
  93.     float conversion, dummy;
  94.  
  95.     [super writePrintInfo];
  96.     pi = [NXApp printInfo];
  97.     [self convertOldFactor:&conversion newFactor:&dummy];
  98.     if (conversion) {
  99.     [pi setMarginLeft:[leftMargin floatValue] / conversion
  100.             right:[rightMargin floatValue] / conversion
  101.               top:[topMargin floatValue] / conversion
  102.            bottom:[bottomMargin floatValue] / conversion];
  103.     }
  104.  
  105.     return self;
  106. }
  107.  
  108. /* outlet setting methods */
  109.  
  110. - setPlpAccessory:anObject
  111. {
  112.     plpAccessory = anObject;
  113.     [self setAccessoryView:plpAccessory];
  114.     [self setSideForm:[plpAccessory findViewWithTag:1]];
  115.     [self setTopBotForm:[plpAccessory findViewWithTag:2]];
  116.     return self;
  117. }
  118.  
  119. - setTopBotForm:anObject
  120. {
  121.     [anObject setTarget:ok];
  122.     [anObject setAction:@selector(performClick:)];
  123.     [anObject setNextText:width];
  124.     [anObject setFloatingPointFormat:NO left:2 right:2];
  125.     topMargin = [anObject findCellWithTag:5];
  126.     [topMargin setEntryType:NX_FLOATTYPE];
  127.     bottomMargin = [anObject findCellWithTag:6];
  128.     [bottomMargin setEntryType:NX_FLOATTYPE];
  129.     return self;
  130. }
  131.  
  132. - setSideForm:anObject
  133. {
  134.     [scale setNextText:anObject];
  135.     [anObject setTarget:ok];
  136.     [anObject setAction:@selector(performClick:)];
  137.     [anObject setFloatingPointFormat:NO left:2 right:2];
  138.     leftMargin = [anObject findCellWithTag:3];
  139.     [leftMargin setEntryType:NX_FLOATTYPE];
  140.     rightMargin = [anObject findCellWithTag:4];
  141.     [rightMargin setEntryType:NX_FLOATTYPE];
  142.     return self;
  143. }
  144.  
  145. @end
  146.  
  147.